﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DistributeTransaction.Models;
using DistributeTransaction.DAL;
using log4net;

namespace DistributeTransaction.Controllers
{
    public class PaymentController : BaseController
    {
        private ILog log = LogManager.GetLogger(typeof(PaymentController));

        //
        // GET: /Payment/

        public ViewResult Index()
        {
            return View(DBContext.Payments.ToList());
        }

        //
        // GET: /Payment/Details/5

        public ViewResult Details(int id)
        {
            Payment payment = DBContext.Payments.Find(id);
            return View(payment);
        }

        //
        // GET: /Payment/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Payment/Create

        [HttpPost]
        public ActionResult Create(Payment payment)
        {
            if (ModelState.IsValid)
            {
                DBContext.Payments.Add(payment);
                DBContext.SaveChanges();
                return RedirectToAction("Index");  
            }

            return View(payment);
        }
        
        //
        // GET: /Payment/Edit/5
 
        public ActionResult Edit(int id)
        {
            Payment payment = DBContext.Payments.Find(id);
            return View(payment);
        }

        //
        // POST: /Payment/Edit/5

        [HttpPost]
        public ActionResult Edit(Payment payment)
        {
            if (ModelState.IsValid)
            {
                DBContext.Entry(payment).State = EntityState.Modified;
                DBContext.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(payment);
        }

        //
        // GET: /Payment/Delete/5
 
        public ActionResult Delete(int id)
        {
            Payment payment = DBContext.Payments.Find(id);
            return View(payment);
        }

        //
        // POST: /Payment/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {            
            Payment payment = DBContext.Payments.Find(id);
            DBContext.Payments.Remove(payment);
            DBContext.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            DBContext.Dispose();
            base.Dispose(disposing);
        }
    }
}